import {
    require
} from "../util/require.js";
// 调用本地存储数据
import userApi from "./ajax.js"

export default {
    // 自己做的表格
    // 获取所有学生数据
    get: async ({
        page = 1,
        limit = 10
    } = {}) => {

        return await require({
            type: "get",
            url: "/api/student",
         
            data: {
                page,
                limit
            },
        });

    },
   
    // 通过_id查询学生
    getOne: async (_id) => {
        return await require({
            type: "get",
            url: `/api/student/${_id}`,
        });
    },
    update: async (student) => {
        return await require({
            type: "put",
            url: `/api/student/${student._id}`,
            data: student

        });

    },
    // 获取学生班级
    getClass: async () => {
        return await require({
            type: "get",
            url: `/api/class`,
        });

    },
    // 添加学生
    post: async (student) => {


        console.log(`1111`,student);
        return await require({
            type: "post",
            url: `/api/student`,
            data: student
        });


    },

// 删除图片接口
    deleteImg: async ({
        _id,
        url
    }) => {
        return await require({
            type: "patch",
            url: `/resource/student/${_id}`,
           data:{url}
        });


    },



    // layui表格
    async layuilist({
        toolbar,
        toolbarhead
    }) {
        return await layui.table.render({
            elem: '#stutable',
            height: 526,
            method: "get",
            url: '/api/student',
            page: true,
            cols: [
                [{
                    type: 'numbers',
                    title: '全选',
                    fixed: 'left'
                }, {
                    type: 'checkbox',
                    fixed: 'left'
                }, {
                    field: 'name',
                    title: '姓名',
                    width: 80
                }, {
                    field: 'age',
                    title: '年龄',
                    width: 80,
                    sort: true
                }, {
                    field: 'sex',
                    title: '性别',
                    width: 80,
                    sort: true
                }, {
                    field: 'classId',
                    title: '班级',
                    width: 80,
                    sort: true
                }, {
                    field: 'tel',
                    title: '电话',
                    width: 150
                }, {
                    field: 'email',
                    title: '邮箱'
                }, {
                    field: 'city',
                    title: '家庭地址'
                }, {
                    fixed: 'right',
                    field: 'tool',
                    title: '操作',
                    width: 120,
                    toolbar: toolbar
                }]
            ],
            toolbar: toolbarhead
        });
    },

    // layui自带重载表格方法(查询)
    async select(data) {
        await layui.table.reload("stutable", {
            url: "/api/student/sel",
            where: data,
            page: {
                curr: 1
            }
        });

    },


}